package com.pearadmin.pro.modules.school.rest;

import com.pearadmin.pro.modules.school.domain.DisciplineCategory;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import  com.pearadmin.pro.modules.school.domain.DisciplineCategory;
import com.pearadmin.pro.modules.school.dto.DisciplineCategoryDTO;
import  com.pearadmin.pro.modules.school.param.DisciplineCategoryRequest;
import  com.pearadmin.pro.modules.school.service.DisciplineCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 学科类别Controller
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Api(tags = {"学科类别"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"disciplineCategory/disciplineCategory")
public class DisciplineCategoryController extends BaseController
{
    @Resource
    private DisciplineCategoryService disciplineCategoryService;

    @GetMapping("/parentList")
    @Log(title = "学科类别父级列表")
    @ApiOperation(value = "学科类别父级列表")
    public Result<DisciplineCategory> parentList(DisciplineCategoryRequest disciplineCategoryRequest)
    {
        disciplineCategoryRequest.setParentDiscipline(Long.getLong("0"));
        return success(disciplineCategoryService.page(disciplineCategoryRequest));
    }

    /**
     * 查询学科类别列表
     *  @return {@link Result}
     */
    @GetMapping("/list")
    @Log(title = "学科类别子列表")
    @ApiOperation(value = "学科类别子列表")
    public Result<DisciplineCategory> list(DisciplineCategoryRequest disciplineCategoryRequest)
    {
        return success(disciplineCategoryService.page(disciplineCategoryRequest));
    }

    /**
     * 查询学科类别列表
     *  @return {@link Result}
     */
    @GetMapping("/tree")
    @Log(title = "学科类别子列表")
    @ApiOperation(value = "学科类别子列表")
    public Result<DisciplineCategoryDTO> tree()
    {
        return success(disciplineCategoryService.tree());
    }

    /**
     * 新增保存学科类别
     * @param disciplineCategory 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增学科类别")
    @ApiOperation(value = "新增学科类别")
    public Result save(@RequestBody DisciplineCategory disciplineCategory)
    {
        return auto(disciplineCategoryService.save(disciplineCategory));
    }

    /**
     * 查询学科类别详情
     *
     * @param id 学科类别ID
     * @return 学科类别
     */
    @GetMapping("/selectById")
    @Log(title = "查询学科类别详情")
    @ApiOperation(value = "查询学科类别详情")
    public Result<DisciplineCategoryDTO> selectById(@RequestParam Long id)
    {
        return success(disciplineCategoryService.selectDisciplineCategoryById(id));
    }



    /**
     * 修改保存学科类别
     * @param disciplineCategory 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改学科类别")
    @ApiOperation(value = "修改学科类别")
    public Result update(@RequestBody DisciplineCategory disciplineCategory)
    {
        return auto(disciplineCategoryService.updateById(disciplineCategory));
    }


    /**
     * 删除保存学科类别
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除学科类别")
    @ApiOperation(value = "删除学科类别")
    public Result remove(@RequestParam Long id)
    {
        return auto(disciplineCategoryService.removeById(id));
    }

    /**
    * 批量删除学科类别
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除学科类别")
    @ApiOperation(value = "批量删除学科类别")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(disciplineCategoryService.removeByIds(ids));
    }

}
